package com.zksk.portal.controller.index;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zksk.common.core.constant.PortalConstants;
import com.zksk.common.core.domain.R;
import com.zksk.common.core.web.controller.BaseController;
import com.zksk.common.log.annotation.Log;
import com.zksk.common.log.enums.BusinessType;
import com.zksk.mbg.admin.domain.Carousel;
import com.zksk.portal.service.finance.CarouselService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 轮播图类 信息操作处理
 *
 * @author zksk
 */
@Slf4j
@RestController
@RequestMapping("/index/banner")
@Api(value = "CarouselController", tags = "门户轮播图相关接口")
public class CarouselController extends BaseController {

    @Autowired
    private CarouselService carouselService;

    @Log(title = "默认门户轮播图查询", businessType = BusinessType.SELECT)
    @ApiOperation(value = "默认门户轮播图查询")
    @GetMapping
    public R<List<Carousel>> defaultList(@RequestParam(value = "platformId",required = false) Long platformId){
        // 现阶段暂与平台模块无联系 默认展示至多六张轮播图
        List<Carousel> list = carouselService.list(new QueryWrapper<Carousel>()
                .eq(ObjectUtil.isNotNull(platformId), Carousel.STATIONS_ID, platformId)
                .eq(Carousel.STATUS, PortalConstants.CAROUSEL_STATUS_0)
                .orderByDesc(Carousel.SORT)
                .last("limit 6"));
        return R.ok(list,"返回轮播图成功");
    }
}
